<template>
	<view class="page">
		<image src="https://hzybucket.obs.cn-south-1.myhuaweicloud.com/we_chat/top-bg.png" class="bg-color"
			mode="aspectFill">
		</image>
		<!--@scroll="pagScroll" :bg-color="scrollTop > 100 ? 'rgba(240, 240, 240,1)' : 'rgba(240, 240, 240,0)'" -->
		<z-paging ref="paging" refresher-only @onRefresh="onRefresh">
			<!--  :bgColor="scrollTop > 100 ? '#fff' : 'rgba(0,0,0,0)'" -->
			<uv-navbar slot="top" bgColor="rgba(0,0,0,0)" autoBack :fixed="false" title="精选案例"></uv-navbar>

			<!-- 内容 -->
			<view class="padidng-box ios">
				<uv-empty marginTop="100" v-if="!dataList.length" mode="list"
					icon="https://hzybucket.obs.cn-south-1.myhuaweicloud.com/we_chat/no-msg2.png" :text="''"
					textColor="rgba(0,0,0,0)"></uv-empty>
				<view class="case-list-box">
					<view class="case-list-item" v-for="(item, index) in dataList" :key="index" @click="preFile(item)">
						<view class="icon-box" v-if="item.file_type == 2">
							<uv-icon name="play-right-fill" size="24" color="#ffffff"></uv-icon>
						</view>
						<image v-if="item.file_type == 1" :src="item.case_list[0].file_url" class="case-list-image"
							mode="aspectFill"></image>
						<video v-else :controls="false" :show-fullscreen-btn="false" :show-play-btn="false"
							:show-center-play-btn="false" :src="item.case_list[0].file_url" class="case-list-image"
							mode="aspectFill"></video>
						<view class="case-list-item-title ellipsis">{{ item.title }}</view>
					</view>
				</view>
			</view>

		</z-paging>

		<!-- 视频预览 -->
		<preVideo :show="preVideoShow" :currVideo="currVideo" @close="maskClick"></preVideo>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				currVideo: '',
				preVideoShow: true,
				dataList: [],
			}
		},
		onLoad() {
			this.getData()
		},
		methods: {
			preFile(item) {
				if (item.file_type == 1) {
					// 图片
					let urls = [];
					item.case_list.forEach((file) => {
						urls.push(file.file_url);
					});
					uni.previewImage({
						urls
					});
				} else {
					this.preVideoShow = true;
					this.currVideo = item.case_list[0].file_url;
				}
			},
			maskClick() {
				this.preVideoShow = false;
				this.currVideo = '';
			},
			// ----------------------------请求数据----------------------------
			onRefresh() {
				this.getData()
			},
			getData() {
				this.$Api.wxHomepageData().then((res) => {
					console.log(res, '小程序配置数据');
					setTimeout(() => {
						// 停止刷新动画
						this.$refs.paging.complete();
					}, 300);
					if (res.code == 200) {
						this.dataList = res.data.case;
					}
				}).catch((err) => {
					setTimeout(() => {
						// 停止刷新动画
						this.$refs.paging.complete();
					}, 300);
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import "index.scss";
</style>